package com.leyou.trade.utils;

/**
 * @author 虎哥
 */
public class UserHolder {
    private static final ThreadLocal<Long> TL = new ThreadLocal<>();

    public static void setUser(Long userId) {
        TL.set(userId);
    }

    public static Long getUser() {
        Long id = TL.get();
        if(id == null){
            // 不存在时返回默认值
            return 0L;
        }
        return id;
    }

    public static void removeUser() {
        TL.remove();
    }
}